package modelLayer;

import java.util.ArrayList;

public class MachineContainer {
    
    private ArrayList<Machine> machines;
    private static MachineContainer instance;
   
    private MachineContainer() {
        machines = new ArrayList<>();
    }
    
    public static MachineContainer getInstance() {
        if (instance == null) {
            instance = new MachineContainer();
        }
        
        return instance;
    }
    
    public void addMachine(Machine mcn) {
        machines.add(mcn);
    }
    
    public Machine findMachine(int barcode) {
        boolean found = false;
        int index = 0;
        while(index < machines.size() && !found) {
            Machine mcn = machines.get(index);
            if(mcn.getBarcode()==(barcode)) {
                found = true;
            }
            else {
                index++;
            }
        }
        
        if(found) {
            return machines.get(index);
        }
        else {
            return null;
        }
    }
    
    public void removeMachine(Machine mcn) {
        machines.remove(mcn);
    }
    
    public int getSize(){
     return machines.size();
    }
    
    
}
    

